<template>
  <div class="list_container">
    <el-table :data="resList" stripe style="width: 100%">
      <el-table-column prop="nickname" label="用户" width="180">
      </el-table-column>
      <el-table-column prop="uid" label="ID" width="180"> </el-table-column>
      <el-table-column prop="mobile" label="手机号" width="180">
      </el-table-column>
      <el-table-column prop="avatar" label="头像" width="180">
        <template slot-scope="scope">
          <img :src="scope.row.avatar" alt="" style="width: 40px" />
        </template>
      </el-table-column>
      <el-table-column prop="created_at" label="日期" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.created_at | timeFilters }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="date" label="操作" width="180">
        <template slot-scope="scope">
          <el-button @click="remove(scope.$index)">删除</el-button>
          <el-button @click="editFun(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="list.length"
      :page-size="page_size"
      :current-page="current_page"
      @current-change="current_change"
    >
    </el-pagination>
    <el-dialog title="收货地址" :visible.sync="dialog">
      <el-form :model="form">
        <el-form-item label="活动名称">
          <el-input v-model="form.nickname" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialog = false">取 消</el-button>
        <el-button type="primary" @click="editok">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      page_size: 25,
      current_page: 1,
      dialog:false,
      form:{
        nickname:"",
        uid:""
      }
    };
  },
  mounted() {
    this.$axios.get("http://localhost:8080/list.json").then((res) => {
      console.log(res.data);
      this.list = res.data;
    });
  },
  filters: {
    timeFilters: function (val) {
      var time = new Date(val * 1000);
      return `${time.getFullYear()}年${time.getMonth()}月${time.getDay()}日${time.getHours()}时${time.getMinutes()}分${time.getUTCMinutes()}秒`;
    },
  },
  computed: {
    resList() {
      return this.list.slice(
        this.page_size * (this.current_page - 1),
        this.page_size * this.current_page
      );
    },
  },
  methods: {
    current_change(val) {
      console.log(val);
      this.current_page = val;
    },
    editFun(val) {
      this.dialog = true;
      console.log(val);
      this.form = val;
    },
    editok() {
      this.dialog = false;
      this.list.forEach((item) => {
        if (this.form.uid == item.uid) {
          this.form = item;
        }
      });
    },
    remove(index) {
      // console.log(index);
      this.list.splice(index, 1);
    },
  },
};
</script>

<style>
</style>